package o;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView.s;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appmarket.service.settings.bean.gameservice.AuthorizedAppInfo;
import com.huawei.appmarket.service.settings.bean.gameservice.CancelGameServiceAuthRes;
import com.huawei.hwid.core.constants.HwAccountConstants;
import huawei.widget.HwButton;
import huawei.widget.HwTextView;
import java.lang.ref.WeakReference;
import java.util.List;
import o.der.f;
import o.der.g;

public class ehe extends androidx.recyclerview.widget.RecyclerView.a<c> {
    private AlertDialog ˊ;
    private WeakReference<Context> ˋ;
    private List<AuthorizedAppInfo> ˎ;
    private d ॱ;

    public interface d {
        void ˊ(boolean z);
    }

    static class a implements OnClickListener {
        private a() {
        }

        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
        }
    }

    public class c extends s {
        public ImageView ʻॱ;
        final /* synthetic */ ehe ʽॱ;
        public HwButton ॱˋ;
        public ImageView ॱᐝ;
        public HwTextView ᐝॱ;

        public c(ehe o_ehe, @NonNull View view) {
            this.ʽॱ = o_ehe;
            super(view);
            this.ॱᐝ = (ImageView) view.findViewById(o.der.d.ʼ);
            this.ᐝॱ = (HwTextView) view.findViewById(o.der.d.ˊॱ);
            this.ॱˋ = (HwButton) view.findViewById(o.der.d.ᐝᐝ);
            this.ʻॱ = (ImageView) view.findViewById(o.der.d.ـ);
        }
    }

    @NonNull
    public /* synthetic */ s ˎ(@NonNull ViewGroup viewGroup, int i) {
        return ˏ(viewGroup, i);
    }

    public /* synthetic */ void ॱ(@NonNull s sVar, int i) {
        ˏ((c) sVar, i);
    }

    public ehe(Context context, List<AuthorizedAppInfo> list) {
        this.ˋ = new WeakReference(context);
        this.ˎ = list;
    }

    @NonNull
    public c ˏ(@NonNull ViewGroup viewGroup, int i) {
        return new c(this, LayoutInflater.from(viewGroup.getContext()).inflate(g.ˍ, viewGroup, false));
    }

    public void ˏ(@NonNull c cVar, final int i) {
        final String ˊ = ((AuthorizedAppInfo) this.ˎ.get(i)).ˊ();
        final Object ॱ = ((AuthorizedAppInfo) this.ˎ.get(i)).ॱ();
        cVar.ᐝॱ.setText(ॱ);
        eqx.ˎ(cVar.ॱᐝ, ((AuthorizedAppInfo) this.ˎ.get(i)).ˋ());
        cVar.ॱˋ.setOnClickListener(new View.OnClickListener(this) {
            final /* synthetic */ ehe ˊ;

            public void onClick(View view) {
                this.ˊ.ˏ(ॱ, ˊ, i);
            }
        });
        if (i == ˏ() - 1) {
            cVar.ʻॱ.setVisibility(8);
        }
    }

    public int ˏ() {
        return this.ˎ == null ? 0 : this.ˎ.size();
    }

    private void ˏ(String str, final String str2, final int i) {
        Context context = (Context) this.ˋ.get();
        if (!(context instanceof Activity)) {
            Logger.ˋ("GameServiceAuthAppAdapter", "context is not an activity");
        } else if (((Activity) context).isFinishing()) {
            Logger.ˋ("GameServiceAuthAppAdapter", "activity is finishing");
        } else {
            Builder builder = new Builder(context);
            builder.setTitle(context.getString(f.ʽˊ, new Object[]{str}));
            builder.setMessage(context.getString(f.ʼᐝ, new Object[]{str}));
            builder.setPositiveButton(f.ॱʿ, new OnClickListener(this) {
                final /* synthetic */ ehe ॱ;

                public void onClick(DialogInterface dialogInterface, int i) {
                    this.ॱ.ॱ(str2, i);
                    dialogInterface.dismiss();
                }
            });
            builder.setNegativeButton(f.ॱʾ, new a());
            this.ˊ = builder.create();
            this.ˊ.setCanceledOnTouchOutside(false);
            this.ˊ.show();
        }
    }

    private void ॱ(String str, final int i) {
        if (doo.ˊ(ContentManager.getInstant().getContext())) {
            Object accessToken = UserSession.getInstance().getAccessToken();
            Logger.ˎ("GameServiceAuthAppAdapter", "accessToken: " + (accessToken == null ? HwAccountConstants.NULL : "not null"));
            if (TextUtils.isEmpty(accessToken)) {
                new eoh().ˎ();
                this.ॱ.ˊ(false);
                return;
            }
            fbh.ˋ(efo.ˎ(str, accessToken), new IServerCallBack(this) {
                final /* synthetic */ ehe ˋ;

                public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
                }

                public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
                    Context context = (Context) this.ˋ.ˋ.get();
                    if (!(context instanceof Activity)) {
                        Logger.ˋ("GameServiceAuthAppAdapter", "context is not an activity");
                    } else if (((Activity) context).isFinishing()) {
                        Logger.ˋ("GameServiceAuthAppAdapter", "activity is finishing");
                    } else if (!(responseBean instanceof CancelGameServiceAuthRes)) {
                        evk.ˏ(ContentManager.getInstant().getContext(), f.ʾॱ, 0).ˋ();
                        this.ˋ.ॱ.ˊ(false);
                    } else if (responseBean.getResponseCode() == 0) {
                        switch (responseBean.getRtnCode_()) {
                            case 0:
                                this.ˋ.ˎ.remove(i);
                                this.ˋ.ˋ(i);
                                this.ˋ.ˊ();
                                evk.ˏ(ContentManager.getInstant().getContext(), f.ʽˋ, 0).ˋ();
                                this.ˋ.ॱ.ˊ(true);
                                return;
                            case 2:
                                Logger.ˎ("GameServiceAuthAppAdapter", "invalid AT, signIn again");
                                evk.ˏ(ContentManager.getInstant().getContext(), f.ʾॱ, 0).ˋ();
                                new eoh().ˎ();
                                this.ˋ.ॱ.ˊ(false);
                                return;
                            default:
                                evk.ˏ(ContentManager.getInstant().getContext(), f.ʾॱ, 0).ˋ();
                                Logger.ˎ("GameServiceAuthAppAdapter", "rntCode: " + responseBean.getRtnCode_() + ", rntDesc: " + ((CancelGameServiceAuthRes) responseBean).ˋ());
                                this.ˋ.ॱ.ˊ(false);
                                return;
                        }
                    } else {
                        evk.ˏ(ContentManager.getInstant().getContext(), f.ʾॱ, 0).ˋ();
                        Logger.ˎ("GameServiceAuthAppAdapter", "rntCode: " + responseBean.getRtnCode_() + ", rntDesc: " + ((CancelGameServiceAuthRes) responseBean).ˋ());
                        this.ˋ.ॱ.ˊ(false);
                    }
                }
            });
            return;
        }
        Logger.ˎ("GameServiceAuthAppAdapter", "no active network");
        evk.ˏ(ContentManager.getInstant().getContext(), f.ʻʽ, 0).ˋ();
    }

    public void ॱ() {
        if (this.ˊ != null && this.ˊ.isShowing()) {
            this.ˊ.dismiss();
            this.ˊ = null;
        }
    }

    public void ˎ(d dVar) {
        this.ॱ = dVar;
    }
}
